package com.gorkr;

import org.junit.jupiter.api.Test;

/**
 * 跳跃游戏
 * @author gorkr
 * @date 2021/12/28 19:54
 **/
public class L55 {

    public boolean canJump(int[] nums) {
        int now = 0;
        int size = nums.length;
        for (int i = 0; i < size; i++) {
            if(i<=now){
                now = Math.max(nums[i]+i,now);
            }else {
                break;
            }
        }

        if(now<(size-1)){
            return false;
        }

        return true;

    }

    @Test
    public void test(){

        int[] nums = {2,3,1,1,4};
        int[] nums2 = {3,2,1,0,4};
        System.out.println(canJump(nums));
    }
}
    